<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title></title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../static/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="../static/css/thesame.css" media="all">
	<link rel="stylesheet" href="../static/css/footer.css" media="all">
	<link rel="stylesheet" href="../static/css/bill/rightCon.css" media="all">
	<link rel="stylesheet" href="../static/css/bill/page.css" media="all">
	<link rel="stylesheet" href="../static/css/bill/popCss.css" media="all">
	<script th:inline="javascript">var basePath = [[${#httpServletRequest.getContextPath()}]];</script>
	<style type="text/css">
		.pointer{cursor: pointer}
		.pop-money-ul li{ overflow: hidden }
		.pop-money-ul li p{ float:left; width:48%; overflow: hidden; line-height: 32px }
		.pop-money-ul li p em,.pop-money-ul li p span{ float: left }
		.pop-money-ul li p em{ width: 100px; text-align: right; font-style:normal }
	</style>
</head>

<body class="layui-layout-body">
<input type="hidden" id="userNo" th:value="${elderlyInfoOfBase.elderlyInfo.userNo}">
<div class="layui-body">
	<div class="add-title pad25px"><span style="cursor: pointer;" onclick="returnBillList()" class="mr10px"><img src="../static/elderlyInfo/img/return_icon.png"></span><span>查看信息</span></div>
	<!-- 内容主体区域 -->
	<div class="new-add-box new-add-box-width bgWhite box-shadows border-radius4">
		<div class="add-box-scroll">
			<div class="border-bot5px border-radius4 pad25px">
				<dl class="per-look-dl">
					<dt th:if="${ #strings.isEmpty(elderlyInfoOfBase.elderlyInfo.imgPath) }">
						<img src="../static/elderlyInfo/img/moren.png" class="block">
					</dt>
					<dt th:if="${ not #strings.isEmpty(elderlyInfoOfBase.elderlyInfo.imgPath) }">
						<img th:src="${elderlyInfoOfBase.elderlyInfo.imgPath}" class="block">
					</dt>

					<!-- nursingCostNo -->
					<dd>
						<div class="overflow">
							<p class="left">
								<span th:text="${elderlyInfoOfBase.elderlyInfo.userName}"></span>
								<span th:text="${elderlyInfoOfBase.buildingInfo}" class="border-bggray"></span>
							</p>
							<p class="right">
								<span  th:if="${elderlyInfoOfBase.elderlyInfo.cognitionStatus != '否'}" class="border-bgred">认知问题</span>
								<span th:onclick="nursingLevelPicLayerOpen([[${elderlyInfoOfBase.nursingCostNo}]])" class="border-bgred">




										<em th:text="${elderlyInfoOfBase.nursingCostName}"></em>
										<em class="look-em border-bgred textCenter">?</em>
									</span>
								<span class="border-bgred" th:text="${elderlyInfoOfBase.assessmentCostName}"></span>
							</p>
						</div>
						<div>
							<span th:text="${elderlyInfoOfBase.elderlyInfo.userSex}"></span>
							<span th:text="${elderlyInfoOfBase.elderlyInfo.age}+'岁'"></span>
							<span th:text="${elderlyInfoOfBase.elderlyInfo.education}"></span>
							<span th:text="${elderlyInfoOfBase.elderlyInfo.socialSecurityType}"></span>
							<span th:text="${elderlyInfoOfBase.elderlyInfo.liveAddress}"></span>
							<!-- <span>本科</span>
                            <span>城保</span>
                            <span>黄渡镇联西村135号</span> -->
							<!-- <p th:text="${userInfo.age}+'岁'"></p> -->
						</div>
						<div>
							<span class="border-bggreen"  th:text="'合同截止：'+${elderlyInfoOfBase.endDate}"  ></span>
							<span class="border-bggreen" th:text="'下次护理评估时间：'+${elderlyInfoOfBase.nextEffectDate}"></span>
							<span class="border-bggreen" th:text="'评估有效期：'+${elderlyInfoOfBase.validDate}"></span>
						</div>
					</dd>
				</dl>
			</div>
			<div>
				<div class="layui-tab layui-tab-time" style="margin: 10px 0 0;">
					<div class="layui-tab-content bgWhite pad25px">
						<div class="layui-tab layui-tab-time" style="margin: 10px 0 0;" lay-filter="totalTab">
							<div class="layui-form">
								<ul class="layui-tab-title pl25px">
									<li lay-id="finance" class="layui-this">财务明细</li>
									<li lay-id="pay">缴费明细</li>
								</ul>
							</div>
							<div class="layui-tab-content bgWhite pad25px">
								<div class="layui-tab-item layui-show finance-layui-carousel">
									<ul class="finance-money overflow pb20px border-bot1px fb">
										<li><span>总费用：</span><em id="tabTotalAmt" th:text="${elderlyInfoOfBase.totalAmt}+'元'"></em></li>
										<li><span>实缴款：</span><em id="tabRealPayAmt" th:text="${elderlyInfoOfBase.realPayAmt}+'元'"></em></li>
										<li><span>应缴款：</span><em id="tabNeedPayAmt" th:text="${elderlyInfoOfBase.needPayAmt}+'元'" class="red"></em><span class="ml20px" id="tabUnsettledMonth" th:text="${elderlyInfoOfBase.unsettledMonth}+'月未结算'"></span></li>
									</ul>
									<article class="pt20px pb20px">
										<div class="overflow">
											<div class="left layui-carousel-year mr50px">
												<div class="layui-carousel" lay-filter="selectYear" id="slide1">
													<div carousel-item>
														<div th:each="yearMonth,yearMonthStat:${elderlyInfoOfBase.settleYearArr}" th:if="${yearMonthStat.last}" th:text="${yearMonth.year}"></div>
														<div th:each="yearMonth,yearMonthStat:${elderlyInfoOfBase.settleYearArr}" th:if="${!yearMonthStat.last}" th:text="${yearMonth.year}"></div>
													</div>
												</div>
											</div>
											<div class="left layui-carousel-month">
												<div class="layui-carousel" id="slide2">
													<div id="showMonth" carousel-item>
													</div>
												</div>
											</div>
										</div>
										<nav id="billQuery" class="month-money mt20px pad20px border-box border1px border-radius4" style="display: none;">
											<div class="fb"><span class="f18px">本月费用</span>（单位：元）</div>
											<ul>
												<li>
													<p id="curNeedPayFee" class="red">0.00</p>
													<p>应缴费用</p>
												</li>
												<li>
													<p>=</p>
													<p></p>
												</li>
												<li>
													<p id="curTotalFee">0</p>
													<p>当月费用</p>
												</li>
												<li>
													<p>-</p>
													<p></p>
												</li>
												<li>
													<p id="curRealPayFee">0</p>
													<p>已缴费用</p>
												</li>
												<li>
													<p id="settleClearImg"><img th:src="@{/static/img/icon_jieqing.png}" alt="" class="block"></p>
												</li>
											</ul>
										</nav>
									</article>

									<div>
										<div class="pt20px pb20px border-bot1px">
											<nav class="detail-nav lh32px">
												<div class="detail-one overflow fb">
													<p class="left"><img th:src="@{/static/img/icon_detail_down.png}">外出情况费用扣除</p>
													<input id="initCalcuDay" type="hidden"/>
													<input id="initTotalAmt" type="hidden"/>
													<input id="initBedFee" type="hidden"/>
													<input id="initNursingFee" type="hidden"/>
													<input id="initMealFee" type="hidden"/>
													<input id="initAssementFee" type="hidden"/>
													<input id="initDayBedFee" type="hidden"/>
													<input id="initDayNursingFee" type="hidden"/>
													<input id="initDayAssementFee" type="hidden"/>
													<input id="initDayMealFee" type="hidden"/>
													<input id="initDayBedCost" type="hidden"/>
													<input id="initDayNursingCost" type="hidden"/>
													<input id="initDayAssementCost" type="hidden"/>
													<input id="initDayMealCost" type="hidden"/>
													<input id="initRealPayAmt" type="hidden"/>
													<input id="initYear" type="hidden"/>
													<input id="initMonth" type="hidden"/>
													<input id="initState" type="hidden"/>
													<input id="initLastBalance" type="hidden"/>
													<input id="initUnsettledMonth" th:value="${elderlyInfoOfBase.unsettledMonth}" type="hidden"/>

													<p class="right">总计：<em id="calcuDay">0</em>天</p>
												</div>
												<article>
													<ul>
														<li>
															<em>住院天数：</em>
															<span><input id="hospitalDay"  onblur="calcuRealDay()" onkeyup="value=value.replace(/[^\d]|^0/g,'')" maxlength="2" type="text"></span>
															<em></em>天</em>
														</li>
														<li>
															<em>请假外出天数：</em>
															<span><input id="leaveDay" onblur="calcuRealDay()" onkeyup="value=value.replace(/[^\d]|^0/g,'')" maxlength="2" type="text"></span>
															<em>天</em>
														</li>
														<li>合计：<em id="excludeDay">0</em>天</li>
													</ul>
												</article>
											</nav>
										</div>
										<div class="pt20px pb20px border-bot1px">
											<nav class="detail-nav lh32px">
												<div class="detail-one overflow fb">
													<p class="left"><img th:src="@{/static/img/icon_detail_down.png}">费用</p>
													<p class="right">总计：<em id="realTotalAmt">0</em>元</p>
												</div>
												<article>
													<div class="gray">计算规则：总床位数+总护理费+总伙食费-长护险补贴+特殊费用</div>
													<ul>
														<li>床位费：<em id="bedFee">0</em>元/日</li>
														<li>床位费总计：<em id="realBedFee">0</em>元</li>
													</ul>
													<ul>
														<li>护理费：<em id="nursingFee">1500</em>元/日</li>
														<li>护理费总计：<em id="realNursingFee">7869</em>元</li>
													</ul>
													<ul class="detail-ul-one">
														<li>伙食费：<em id="dayMealFee">0</em>元/日</li>
													</ul>
													<ul>
														<li>
															<em>伙食费扣除：</em>
															<span><input id="mealSubFee" onblur="calcuRealMealFee()" onkeyup="value=value.replace(/[^\d]|^0/g,'')" type="text"></span>
															<em>元</em>
														</li>
														<li>伙食费总计：<em id="realMealFee">0</em>元</li>
													</ul>
												</article>
											</nav>
										</div>
										<div class="pt20px pb20px border-bot1px">
											<nav class="detail-nav lh32px">
												<div class="detail-one overflow fb"	>
													<p class="left"><img th:src="@{/static/img/icon_detail_down.png}">长护险补贴</p>
													<p class="right">总计：<em id="assementFee">0</em>元</p>
												</div>
												<article>
													<div class="gray">计算规则：-(评估等级补贴+长护险扣除)</div>
													<ul>
														<li>评估等级（四级）：<em id="assementMonthFee">0</em>元/月</li>
														<li>长护险补贴总计：<em id="realAssementFee">0</em>元</li>
													</ul>
													<ul class="detail-ul-one">
														<li>
															<em>长护险扣除：</em>
															<span><input id="assementSubFee" onblur="calcuRealAssementFee()" onkeyup="value=value.replace(/[^\d]|^0/g,'')" type="text"></span>
															<em>元</em>
														</li>
													</ul>
												</article>
											</nav>
										</div>
										<div class="pt20px pb20px border-bot1px">
											<nav class="detail-nav lh32px">
												<div class="detail-one overflow fb">
													<p class="left"><img th:src="@{/static/img/icon_detail_down.png}">特殊费用</p>
													<p class="right">总计：<em id="realSpecialFee">0</em>元</p>
												</div>
												<article>
													<ul class="detail-ul-one">
														<li>
															<em>特殊费用：</em>
															<span><input id="specialFee" onblur="calcuRealSpecialFee()" onkeyup="value=value.replace(/[^\d|-]|^0/g,'')" type="text"></span>
															<em>元</em>
														</li>
													</ul>
													<div>
														<textarea id="specialFeeRemark" maxlength="100" rows="3" cols="5" class="resize border1px border-radius4 pad12px border-box mt10px" style="width: 100%;"></textarea>
													</div>
												</article>
											</nav>
										</div>
									</div>
								</div>
								<div class="layui-tab-item">
									<div class="pb25px mb25px border-bot1px lh32px overflow">
										<p class="left">时间范围：</p>
										<p class="left layui-time-img">
											<span class="layui-input-inline" style="width: 200px;">
												<input type="text" id="startDay" placeholder="" class="layui-input time-img test-item">
											</span>
											<span>&nbsp;至&nbsp;</span>
											<span class="layui-input-inline" style="width: 200px;">
												<input type="text" id="endDay" placeholder="" class="layui-input time-img test-item2">
											</span>
										</p>
										<p class="left ml40px pointer"><span style="display: inline-block" onclick="pay_bilListGenerate()" class="white border-radius4 bgGreen block pl20px pr20px mr20px">查&nbsp;询</span></p>
									</div>
									<div class="mb20px lh32px overflow add-btn-input">
										<p class="left cursor">
											<span onclick="layerBillPay()" class="white border-radius4 bgGreen inline-block pl15px pr15px mr25px"><img th:src="@{/static/img/button_add.png}">新建</span>
<!--											<span class="white border-radius4 bgRed inline-block pl15px pr15px"><img th:src="@{/static/img/icon_delete.png}" style="vertical-align: -2px;">删除</span><span class="white border-radius4 bgRed inline-block pl15px pr15px"><img th:src="@{/static/img/icon_delete.png}" style="vertical-align: -2px;">删除</span>-->
										</p>
										<p class="right">共有<span id="payBillTotal" class="red">0</span>条数据</p>
									</div>
									<div class="border1px border-radius4 relative mb40px">
										<table class="layui-hide" id="paybillList" lay-filter="test"></table>
									</div>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="layui-footer layui-footer-one">
	<div class="pointer btn-con textCenter">
		<span id="financeSettleBtn" style="background-color: #1C9399;color: #fff;" onclick="layerSettle()">结&nbsp;算</span>
	</div>
</div>
</body>
<script src="../static/js/jquery-2.1.3.min.js"></script>
<script src="../static/js/BigDecimal.js"></script>
<script type="text/javascript" th:src="@{/static/js/layuiCon.js}" charset="utf-8"></script>
<script src="../static/layui/layui.js" charset="utf-8"></script>
<script>
	//layer初始化
	var layer;
	layui.use(['element','laydate','layer'], function() {
		var element = layui.element;
		layer = layui.layer;
		var laydate = layui.laydate;
		laydate.render({
			elem: '.test-item',
			trigger: 'click',
			max:getCurDate(),
		});

		laydate.render({
			elem: '.test-item2',
			trigger: 'click',
			max:getCurDate(),
		});

		//监听Tab切换
		element.on('tab(totalTab)', function(){
			var id = this.getAttribute('lay-id');
			if(id=="finance"){
				$("#financeSettleBtn").show();
			}else if(id=="pay"){
				$("#financeSettleBtn").hide();
			}
		});

	});


	var financeFirstFlag=true;	//账务明细-第一次进入默认显示入住最后一个月

	$(function() {
		/* $('.detail-one article').hide(); */
		//财务明细-下拉选择初始化
		financeInfoSelectInit();
		//账务明细-账单年份选择初始化
		layui_financeYearSelectInit();
		//财务明细-账单月份选择初始化
		layui_financeMonthSelectInit();
		//缴费明细-缴费列表初始化
		pay_bilListGenerate();

	})

	/**
	 * 返回列表
	 */
	function returnBillList(){
		window.location.href=basePath+"/bill/listPage";
	}

	/**
	 * 获取账单选择年份的月份
	 */
	function getMonthArrOfBillYear(year){
		var userNo = '[[${elderlyInfoOfBase.elderlyInfo.userNo}]]';
		$.ajax({
			type:"post",
			url:basePath+"/bill/getMonthArrOfBillYear",
			dataType:"json",
			async: false,
			data:{"userNo":userNo,"year":year},
			success:function(r){
				if(r.code==200){
					var data1="<div><ul id=\"showMonth1\" class=\"finance-month\">";
					var data2="<div><ul id=\"showMonth2\" class=\"finance-month\">";
					$.each(r.data.data1,function(index,obj){
						data1+=(obj.status==1)?'<li data-state="'+obj.status+'">'+obj.month+'</li>':'<li data-state="'+obj.status+'" style="color: #ccc">'+obj.month+'</li>';
					});
					data1+='</ul></div>';

					$.each(r.data.data2,function(index,obj){
						data2+=(obj.status==1)?'<li data-state="'+obj.status+'">'+obj.month+'</li>':'<li data-state="'+obj.status+'" style="color: #ccc">'+obj.month+'</li>';
					});
					data2+='</ul></div>';

					$("#showMonth").html('');
					//第一次进入明细账单,如果是当年，标注当前月
					if(financeFirstFlag){
						$("#showMonth").append(data2);
						$("#showMonth").append(data1);
						$("#showMonth2 li[data-state=1]:last").addClass("month-current");
						var	year = '[[${elderlyInfoOfBase.selectCurYear}]]';
						var month = $(".month-current").html();
						//获取用户月结算信息
						getUserMonthSettleInfo(year,month);
						financeFirstFlag=false;
					}else{
						$("#showMonth").append(data1);
						$("#showMonth").append(data2);
					}

				}
			}
		})

	}

	/**
	 * 财务明细-明细下拉选择初始化
	 */
	function financeInfoSelectInit(){
		$('.detail-one').unbind().click(function() {
			$(this).next().slideToggle(300);
			if ($(this).find('img').attr('src')=='/ATPension/static/img/icon_detail_up.png') {
				$(this).find('img').attr('src', basePath+'/static/img/icon_detail_down.png');
			} else {
				$(this).find('img').attr('src', basePath+'/static/img/icon_detail_up.png');
			}
		})
		// $('.detail-one .left').unbind().click(function() {
		// 	$(this).parent().next().slideToggle(300);
		// 	if ($(this).parent().find('img').attr('src')=='/ATPension/static/img/icon_detail_up.png') {
		// 		$(this).parent().find('img').attr('src', basePath+'/static/img/icon_detail_down.png');
		// 	} else {
		// 		$(this).parent().find('img').attr('src', basePath+'/static/img/icon_detail_up.png');
		// 	}
		// })
	}

	/**
	 * 财务明细-layui年份选择初始化
	 */
	function layui_financeYearSelectInit(){

		//layui初始化
		layui.use(['carousel'], function() {
			var carousel = layui.carousel;
			carousel.render({
				elem: '#slide1'
				,width: '' //设置容器宽度
				,height: '42px'
				,arrow: 'always' //始终显示箭头
				//,anim: 'updown' //切换动画方式
				,indicator: 'none'
				,autoplay: false
			});

			//监听月份轮播切换事件
			carousel.on('change(selectYear)', function(obj){
				var year = obj.item.html();
				//setFinanceFirstFlag();
				//获取账单选择年份的月份
				layui_financeMonthSelectInit(year);
			})
		});
	}

	/**
	 * 财务明细-layui月份选择初始化
	 */
	function layui_financeMonthSelectInit(year){
		//重置月份选择
		$("#showMonth1").parent().addClass("layui-this");
		$("#showMonth2").parent().removeClass("layui-this");

		if(isNull(year)){
			year = '[[${elderlyInfoOfBase.selectCurYear}]]'
		}
		//获取月份
		getMonthArrOfBillYear(year);

		//layui初始化
		layui.use(['carousel'], function() {
			var carousel = layui.carousel;
			var ins=carousel.render({
				elem: '#slide2'
				,width: '' //设置容器宽度
				,height: '42px'
				,arrow: 'always' //始终显示箭头
				//,anim: 'updown' //切换动画方式
				,indicator: 'none'
				,autoplay: false
			});

			//财务时间选择-月份切换
			$('.finance-month li').unbind().click(function(){
				var status = $(this).data("state");
				if(status==1){
					$(this).addClass('month-current').siblings().removeClass('month-current');
					var month = $(this).html();
					//获取用户月结算信息
					getUserMonthSettleInfo(year, month);
				}
			})
		});
	}

	/**
	 * 判断是否
	 */
	function isNull(value) {
		return value == null || value === "" || value === undefined;
	}

	/**
	 * 空值返回0
	 */
	function nullToZero(value) {
		if(value == null || value === "" || value === undefined){
			return 0;
		}else{
			return value;
		}
	}
	/**
	 * 获取用户月份结算信息（当未结算，获取初始结算信息；已结算，获取结算后信息）
	 */
	function getUserMonthSettleInfo(year, month){
		var userNo = '[[${elderlyInfoOfBase.elderlyInfo.userNo}]]';
		$.ajax({
			type:"post",
			url:basePath+"/bill/getUserMonthSettleInfo",
			dataType:"json",
			async: false,
			data:{"userNo":userNo,"year":year,"month":month},
			success:function(r){
				//console.log(r);
				if(r.code==200){
					var state = r.data.state;
					//结算初始化
					//console.log(r.data.tab.tabNeedPayAmt);
					$("#tabTotalAmt").html(r.data.tab.tabTotalAmt+"元");						//总费用
					$("#tabRealPayAmt").html(r.data.tab.tabRealPayAmt+"元");					//实付款
					$("#tabNeedPayAmt").html(r.data.tab.tabNeedPayAmt+"元");					//应付款
					$("#tabUnsettledMonth").html(r.data.tab.tabUnsettledMonth+"月未结算");		//标记几月未结算
					$("#initUnsettledMonth").val(r.data.tab.tabUnsettledMonth);					//几月未结算
					$("#initLastBalance").val(r.data.tab.tabBalance);							//上月结余

					$("#initYear").val(year);								//初始年份
					$("#initMonth").val(month);								//初始月份
					$("#initState").val(state);								//初始状态

					$("#initCalcuDay").val(r.data.calcuDay);				//初始总计天数
					$("#calcuDay").html(r.data.calcuDay);

					$("#initBedFee").val(r.data.initInfo.bedFee);				//初始月床位费
					$("#initDayBedFee").val(r.data.initDayInfo.bed_fee);		//初始日床位费
					$("#initDayBedCost").val(r.data.initDayInfo.bed_cost_no);	//初始床位等级
					$("#bedFee").html(r.data.initDayInfo.bed_fee);
					$("#realBedFee").html(r.data.initInfo.bedFee);

					$("#initNursingFee").val(r.data.initInfo.nursingFee);  			//初始月护理费
					$("#initDayNursingFee").val(r.data.initDayInfo.nurse_fee);		//初始日护理费
					$("#initDayNursingCost").val(r.data.initDayInfo.nurse_cost_no);	//初始护理等级
					$("#nursingFee").html(r.data.initDayInfo.nurse_fee);
					$("#realNursingFee").html(r.data.initInfo.nursingFee);

					$("#initMealFee").val(r.data.initInfo.mealFee);				//初始月伙食费
					$("#initDayMealFee").val(r.data.initDayInfo.food_fee)		//初始日伙食费
					$("#initDayMealCost").val(r.data.initDayInfo.food_cost_no);	//初始伙食费等级
					$("#dayMealFee").html(r.data.initDayInfo.food_fee);
					$("#realMealFee").html(r.data.initInfo.mealFee);

					$("#initAssementFee").val(r.data.initInfo.assementFee);				//初始长护险月护理费
					$("#initDayAssementFee").val(r.data.initDayInfo.assess_fee);		//初始长护险月护理费
					$("#initDayAssementCost").val(r.data.initDayInfo.assess_cost_no);	//初始伙食费等级
					$("#assementFee").html(r.data.initInfo.assementFee);
					$("#assementMonthFee").html(r.data.initInfo.assementFee);
					$("#realAssementFee").html(r.data.initInfo.assementFee);

					$("#initRealPayAmt").val(r.data.realPayAmt);	//该月实际支付

					//计算初始总费用
					var bedFeeBd = $("#initBedFee").val();
					var nursingFeeBd = $("#initNursingFee").val();
					var mealFeeBd = $("#initMealFee").val();
					var assementFeeBd = $("#initAssementFee").val();
					var totalFee = new BigDecimal("0");
					totalFee = totalFee.add(new BigDecimal(bedFeeBd));
					totalFee = totalFee.add(new BigDecimal(nursingFeeBd));
					totalFee = totalFee.add(new BigDecimal(mealFeeBd));
					totalFee = totalFee.subtract(new BigDecimal(assementFeeBd));
					$("#initTotalAmt").val(totalFee.setScale(2, MathContext.ROUND_HALF_UP).toString());
					$("#realTotalAmt").html(totalFee.setScale(2, MathContext.ROUND_HALF_UP).toString());
					if(state==1){
						$("#hospitalDay").val(r.data.bill.hospitalDay);
						$("#leaveDay").val(r.data.bill.outDay);
						$("#mealSubFee").val(r.data.bill.mealDeduct);
						$("#assementSubFee").val(r.data.bill.assementDeduct);
						$("#specialFee").val(r.data.bill.specialFee);
						$("#specialFeeRemark").val(r.data.bill.specialFeeRemark);

						var curMonthFeeBd = new BigDecimal(r.data.bill.curMonthFee.toString());
						var curRealPayFeeBd = new BigDecimal(r.data.realPayAmt.toString());
						//计算当月需缴费用 =计算后的当月月账单-当月实缴费用
						var curNeedPayFee = curMonthFeeBd.subtract(curRealPayFeeBd).setScale(2, MathContext.ROUND_HALF_UP).toString();
						$("#curTotalFee").html(parseFloat(r.data.bill.curMonthFee));
						$("#curRealPayFee").html(parseFloat(r.data.realPayAmt));
						$("#curNeedPayFee").html(parseFloat(curNeedPayFee));


						//应缴费用为0时，显示已结清
						if(parseFloat(curNeedPayFee)>0){
							$("#settleClearImg").hide();
						}else{
							$("#settleClearImg").show();
						}
						//计算实际天数
						calcuRealDay();
						//计算伙食费
						calcuRealMealFee();
						//计算床位费
						calcuRealBedFee();
						//计算护理费
						calcuRealNursingFee();
						//计算长护险费
						calcuRealAssementFee();
						//计算特殊费
						calcuRealSpecialFee();
						$("#hospitalDay").attr("disabled","true");
						$("#leaveDay").attr("disabled","true");
						$("#mealSubFee").attr("disabled","true");
						$("#assementSubFee").attr("disabled","true");
						$("#specialFee").attr("disabled","true");
						$("#specialFeeRemark").attr("disabled","true");
						$("#billQuery").show();
					}else{
						$("#hospitalDay").val(null);
						$("#leaveDay").val(null);
						$("#mealSubFee").val(null);
						$("#assementSubFee").val(null);
						$("#specialFee").val(null);
						$("#specialFeeRemark").val(null);
						$("#excludeDay").html(0);
						$("#hospitalDay").removeAttr("disabled");
						$("#leaveDay").removeAttr("disabled");
						$("#mealSubFee").removeAttr("disabled");
						$("#assementSubFee").removeAttr("disabled");
						$("#specialFee").removeAttr("disabled");
						$("#specialFeeRemark").removeAttr("disabled");
						$("#billQuery").hide();
					}
				}
			}
		})

	}

	/**
	 * 计算实际天数
	 */
	function calcuRealDay(){
		var calcuDay = $("#initCalcuDay").val();
		var hospitalDay = nullToZero($("#hospitalDay").val());
		var leaveDay = nullToZero($("#leaveDay").val());
		var realDay = 0;

		if(parseInt(hospitalDay)>parseInt(calcuDay)){
			layer.msg("住院天数不能超过总计天数！");
			$("#hospitalDay").val(null);
			$("#excludeDay").html(0);
			$("#calcuDay").html(calcuDay);
			//刷新费用
			calcuRealMealFee();
			calcuRealBedFee();
			calcuRealNursingFee();
			calcuRealAssementFee();
			calcuRealSpecialFee();
			return;
		}
		if(parseInt(leaveDay)>parseInt(calcuDay)){
			layer.msg("请假天数不能超过总计天数！");
			$("#leaveDay").val(null);
			$("#excludeDay").html(0);
			$("#calcuDay").html(calcuDay);
			//刷新费用
			calcuRealMealFee();
			calcuRealBedFee();
			calcuRealNursingFee();
			calcuRealAssementFee();
			calcuRealSpecialFee();
			return;
		}
		if(parseInt(hospitalDay)+parseInt(leaveDay)>parseInt(calcuDay)){
			layer.msg("住院天数+请假天数不能超过总计天数！");
			$("#hospitalDay").val(null);
			$("#leaveDay").val(null);
			$("#excludeDay").html(0);
			$("#calcuDay").html(calcuDay);
			//刷新费用
			calcuRealMealFee();
			calcuRealBedFee();
			calcuRealNursingFee();
			calcuRealAssementFee();
			calcuRealSpecialFee();
			return;

		}

		//计算实际天数
		var excludeDay =parseInt(hospitalDay)+parseInt(leaveDay);
		calcuDay = parseInt(calcuDay)-parseInt(excludeDay);
		$("#excludeDay").html(excludeDay);
		$("#calcuDay").html(calcuDay);
		//计算伙食费
		calcuRealMealFee();
		//计算床位费
		calcuRealBedFee();
		//计算护理费
		calcuRealNursingFee();
		//计算长护险费
		calcuRealAssementFee();
		//计算特殊费
		calcuRealSpecialFee();
	}

	/**
	 * 计算实际伙食费
	 */
	function calcuRealMealFee(){
		 var initMealFee = $("#initMealFee").val();				//月伙食费
		 var initDayMealFee = $("#initDayMealFee").val();		//日伙食费
		 var excludeDay = nullToZero($("#excludeDay").html());	//排除合计天数
		 var mealSubFee = nullToZero($("#mealSubFee").val());	//扣除伙食费
		 //计算实际伙食费
		 var excludeAmt = new BigDecimal(initDayMealFee.toString()).multiply(new BigDecimal(excludeDay.toString()));  //排除合计伙食费
		 var mealSubFeeAmt = new BigDecimal(mealSubFee.toString());//扣除伙食费
		 var realMealAmt = new BigDecimal(initMealFee.toString());
		 realMealAmt = realMealAmt.subtract(excludeAmt);
		//如果伙食费用-伙食每日费用*合计天数<0 ,伙食费用=0
		if(realMealAmt<0){
			realMealAmt = new BigDecimal(0);
		}
		 realMealAmt = realMealAmt.subtract(mealSubFeeAmt);
		 realMealAmt = realMealAmt.setScale(2, MathContext.ROUND_HALF_UP).toString();
		 if(realMealAmt<0){
			 layer.msg("伙食费扣除不能超过当月伙食费总计！");
			 $("#mealSubFee").val(null);
			 calcuRealMealFee();
			 return;
		 }
		 $("#realMealFee").html(realMealAmt);
		 //计算实际总费用
		 setRealTotalFee();

	}

	/**
	 * 计算实际床位费
	 */
	function calcuRealBedFee(){
		var initBedFee = $("#initBedFee").val();				//月床位费
		var initDayBedFee = $("#initDayBedFee").val();			//日床位费
		var hospitalDay = nullToZero($("#hospitalDay").val());	//住院天数
		//计算实际床位费
		var excludeAmt = new BigDecimal(initDayBedFee.toString()).multiply(new BigDecimal(hospitalDay.toString()));  //排除合计床位费
		var realBedAmt = new BigDecimal(initBedFee.toString());
		realBedAmt = realBedAmt.subtract(excludeAmt);
		realBedAmt = realBedAmt.setScale(2, MathContext.ROUND_HALF_UP).toString();
		//如果床位费用-床位每日费用*合计天数<0 ,床位费用=0
		if(realBedAmt<0){
			realBedAmt = parseFloat(0);
		}
		$("#realBedFee").html(realBedAmt);
	}

	/**
	 * 计算实际护理费
	 */
	function calcuRealNursingFee(){
		var initNursingFee = $("#initNursingFee").val();			//月护理费
		var initDayNursingFee = $("#initDayNursingFee").val();		//日护理费
		var excludeDay = nullToZero($("#excludeDay").html());		//排除合计天数
		//计算实际护理费
		var excludeAmt = new BigDecimal(initDayNursingFee.toString()).multiply(new BigDecimal(excludeDay.toString()));  //排除合计床位费
		var realNursingAmt = new BigDecimal(initNursingFee.toString());
		realNursingAmt = realNursingAmt.subtract(excludeAmt);
		realNursingAmt = realNursingAmt.setScale(2, MathContext.ROUND_HALF_UP).toString();
		//如果护理费用-护理每日费用*合计天数<0 ,护理费用=0
		if(realNursingAmt<0){
			realNursingAmt=parseFloat(0);
		}
		$("#realNursingFee").html(realNursingAmt);
	}

	/**
	 * 计算实际长护险费
	 */
	function calcuRealAssementFee(){
		var initAssementFee = $("#initAssementFee").val();				//月长护险费
		var initDayAssementFee = $("#initDayAssementFee").val();		//日长护险费
		var excludeDay = nullToZero($("#excludeDay").html());			//排除合计天数
		var assementSubFee = nullToZero($("#assementSubFee").val());	//扣除长护险费
		//计算实际长护险费
		var excludeAmt = new BigDecimal(initDayAssementFee.toString()).multiply(new BigDecimal(excludeDay.toString()));  //排除合计床位费
		var realAssementAmt = new BigDecimal(initAssementFee.toString());
		var assementSubAmt = new BigDecimal(assementSubFee.toString());
		realAssementAmt = realAssementAmt.subtract(excludeAmt);
		//如果长护险费用-长护险每日费用*合计天数<0 ,长护险费用=0
		if(realAssementAmt<0){
			realAssementAmt = new BigDecimal(0);
		}
		realAssementAmt = realAssementAmt.add(assementSubAmt);
		realAssementAmt = realAssementAmt.setScale(2, MathContext.ROUND_HALF_UP).toString();

		var bedFeeBd = nullToZero($("#realBedFee").html());
		var nursingFeeBd = nullToZero($("#realNursingFee").html());
		var mealFeeBd = nullToZero($("#realMealFee").html());
		var specialFeeBd = nullToZero($("#realSpecialFee").html());
		var totalFee = new BigDecimal("0");
		totalFee = totalFee.add(new BigDecimal(bedFeeBd.toString()));
		totalFee = totalFee.add(new BigDecimal(nursingFeeBd.toString()));
		totalFee = totalFee.add(new BigDecimal(mealFeeBd.toString()));
		totalFee = totalFee.subtract(new BigDecimal(realAssementAmt.toString()));
		totalFee = totalFee.add(new BigDecimal(specialFeeBd.toString()));
		//console.log("totalFee="+totalFee);
		if(totalFee<0){
			layer.msg("长护险扣除不能超过当月费用总计！");
			$("#assementSubFee").val(null);
			calcuRealAssementFee();
			return;
		}
		$("#realAssementFee").html(realAssementAmt);
		$("#assementFee").html(realAssementAmt);
		//计算实际总费用
		setRealTotalFee();
	}

	/**
	 * 计算特殊费
	 */
	function calcuRealSpecialFee(){
		var specialFee = nullToZero($("#specialFee").val());			//特殊费用

		$("#specialFee").html(specialFee);
		$("#realSpecialFee").html(specialFee);
		//计算实际总费用
		setRealTotalFee();
	}

	/**
	 * 计算实际总费用
	 */
	function setRealTotalFee(){
		var bedFeeBd = nullToZero($("#realBedFee").html());
		var nursingFeeBd = nullToZero($("#realNursingFee").html());
		var mealFeeBd = nullToZero($("#realMealFee").html());
		var assementFeeBd = nullToZero($("#realAssementFee").html());
		var specialFeeBd = nullToZero($("#realSpecialFee").html());
		var totalFee = new BigDecimal("0");
		totalFee = totalFee.add(new BigDecimal(bedFeeBd.toString()));
		totalFee = totalFee.add(new BigDecimal(nursingFeeBd.toString()));
		totalFee = totalFee.add(new BigDecimal(mealFeeBd.toString()));
		totalFee = totalFee.subtract(new BigDecimal(assementFeeBd.toString()));
		totalFee = totalFee.add(new BigDecimal(specialFeeBd.toString()))
		//初始总费用
		$("#realTotalAmt").html(totalFee.setScale(2, MathContext.ROUND_HALF_UP).toString());
	}

	/**
	 * 打开结算弹窗
	 */
	function layerSettle(){
		var state = $("#initState").val();
		console.log("state="+state);
		if(state==1){
			layer.msg("该账单已结算");
			return;
		}
		// var calcuDay = $("#calcuDay").html();
		// if(calcuDay==0){
		// 	layer.msg("没有账单数据存在，不需要结算");
		// 	return;
		// }
		var unsettledMonth = $("#initUnsettledMonth").val();		 //最老的未结算月份
		var month = $("#initMonth").val();							 //账单月份
		if(unsettledMonth!=month){
			layer.msg("该月前存在未结算月份，请先结算");
			return;
		}

		var curAmt = parseFloat($("#realTotalAmt").html());	//本月费用
		var lastBalance = $("#initLastBalance").val(); //上月结余
		var curRealPayAmt = parseFloat($("#initRealPayAmt").val()); //本月实缴
		var curTotalAmt = getCurMonthTotalAmt(curAmt,lastBalance);  //本月合计费用
		var curBalance = getCurMonthBalance(curRealPayAmt,curAmt,lastBalance); //本月结余

		// console.log("curAmt="+curAmt);
		// console.log("lastBalance="+lastBalance);
		// console.log("curRealPayAmt="+curRealPayAmt);
		// console.log("curTotalAmt="+curTotalAmt);
		// console.log("curBalance="+curBalance);

		var html='';
		html+='<div id="pop-con">';
		html+='<div class="pop-up">';
		html+='<div>';
		html+='<div class="pop-title relative overflow mb15px">';
		html+='<span class="ml15px">结算</span>';
		html+='<p class="right"><img style="cursor: pointer;" src="'+basePath+'/static/img/close_icon.png" class="block pop-close"><p>';
		html+='</div>';
		html+='<ul class="pop-money-ul mt25px mb40px border1px border-radius4 pad20px">';
		html+='<li>';
		html+='<p><em>本月费用：</em><span style="font-size: 16px;"  class="f18px fb">'+curAmt+'</span>元</p>';
		html+=parseFloat(lastBalance)>0?'<p><em>上月结余：</em><span>'+lastBalance+'</span>元</p>':'<p><em>上月结余：</em><span class="red">'+lastBalance+'</span>元</p>';
		html+='</li>';
		html+='<li>';
		html+='<p><em>本月实缴：</em><span>'+curRealPayAmt+'</span>元</p>';
		html+='<p><em>本月费用合计：</em><span style="font-size: 16px;" class="f18px fb">'+curTotalAmt+'</span>元</p>';
		html+='</li>';
		html+='<li>';
		html+=parseFloat(curBalance)>0?'<p><em>本月结余：</em><span>'+curBalance+'</span>元</p>':'<p><em>本月结余：</em><span class="red">'+curBalance+'</span>元</p>';
		html+='</li>';
		html+='</ul>';
		html+='<div class="btn-con textCenter">';
		html+='<span class="btn-settle" style="width: 120px;background-color: #1C9399;color: #fff;cursor: pointer;">确认结算</span>';
		html+='</div>';
		html+='</div>';
		html+='</div>';

		var index = layer.open({
			type: 1,
			title: false, //不显示标题栏
			closeBtn: false,
			area: ['500px', ''],
			shade: 0.6,
			id: 'settleCons', //设定一个id，防止重复弹出
			/*,btn: ['确认支付']*/
			btnAlign: 'c',
			moveType: 1, //拖拽模式，0或者1
			shadeClose: true, //设置允许点遮罩关闭
			content: html,
			success: function() {
				//关闭弹层
				$(".pop-close").unbind().click(function() {
					layer.closeAll();
				});
				$(".btn-settle").unbind().click(function() {
					confirmSettle(curAmt,lastBalance,curRealPayAmt,curTotalAmt,curBalance);
				});
			},

		});
	}

	/**
	 * 确认结算
	 */
	function confirmSettle(curMonthFee,lastBalance,curRealPayAmt,curTotalFee,curBalance){
		var args=[];
		args.push(curMonthFee);
		args.push(lastBalance);
		args.push(curRealPayAmt);
		args.push(curTotalFee);
		args.push(curBalance);
		confirmCon("确认要结算吗？",settleCommit, args);
	}

	/**
	 * 结算提交
	 * curMonthFee		本月费用
	 * lastBalance		上月结余
	 * curRealPayAmt	本月实缴费用
	 * curTotalFee		总费用统计
	 * curBalance		本月结余
	 *
	 */
	function settleCommit(curMonthFee,lastBalance,curRealPayAmt,curTotalFee,curBalance){

		var userNo = '[[${elderlyInfoOfBase.elderlyInfo.userNo}]]';  //用户编号
		var year = $("#initYear").val();							 //账单年份
		var month = $("#initMonth").val();							 //账单月份
		var totalDay = $("#calcuDay").html();						 //总天数
		var hospitalDay = nullToZero($("#hospitalDay").val());	 	 //住院天数
		var outDay = nullToZero($("#leaveDay").val());				 //请假天数
		var bedDegree = $("#initDayBedCost").val();				     //床位等级
		var nursingDegree = $("#initDayNursingCost").val();			 //护理等级
		var assementDegree = $("#initDayAssementCost").val();		 //长护险等级
		var mealFee = $("#realMealFee").html();						 //伙食费
		var mealDeduct = nullToZero($("#mealSubFee").val());		 //伙食费扣除
		var bedFee = $("#realBedFee").html();						 //床位费
		var nursingFee = $("#realNursingFee").html();				 //护理费
		var assementFee = $("#realAssementFee").html();				 //长护险费
		var assementDeduct = nullToZero($("#assementSubFee").val()); //长护险费扣除
		var specialFee = nullToZero($("#realSpecialFee").html());	 //特殊费用
		var specialFeeRemark = $("#specialFeeRemark").val();		 //特殊费用备注

		// console.log("userNo="+userNo);
		// console.log("year="+year);
		// console.log("month="+month);
		// console.log("totalDay="+totalDay);
		// console.log("hospitalDay="+hospitalDay);
		// console.log("outDay="+outDay);
		//
		// console.log("curMonthFee="+curMonthFee);
		// console.log("lastBalance="+lastBalance);
		// console.log("curRealPayAmt="+curRealPayAmt);
		// console.log("curTotalAmt="+curTotalFee);
		// console.log("curBalance="+curBalance);
		//
		// console.log("bedDegree="+bedDegree);
		// console.log("nursingDegree="+nursingDegree);
		// console.log("assementDegree="+assementDegree);
		//
		// console.log("mealFee="+mealFee);
		// console.log("mealDeduct="+mealDeduct);
		// console.log("bedFee="+bedFee);
		// console.log("nursingFee="+nursingFee);
		// console.log("assementFee="+assementFee);
		// console.log("assementDeduct="+assementDeduct);
		// console.log("specialFee="+specialFee);
		// console.log("specialFeeRemark="+specialFeeRemark);

		$.ajax({
			type:"post",
			url:basePath+"/bill/createMonthBill",
			dataType:"json",
			async: false,
			data:{"userNo":userNo,"billYear":year,"billMonth":month,"totalDay":totalDay,"hospitalDay":hospitalDay,"outDay":outDay,
					 "curMonthFee":curMonthFee,"lastBalance":lastBalance,"curRealPayFee":curRealPayAmt,
					 "curTotalFee":curTotalFee,"curBalance":curBalance,
					 "bedDegree":bedDegree,"nursingDegree":nursingDegree,"assementDegree":assementDegree,
					 "mealFee":mealFee,"mealDeduct":mealDeduct,"bedFee":bedFee,
					 "nursingFee":nursingFee,"assementFee":assementFee,"assementDeduct":assementDeduct,
					 "specialFee":specialFee,"specialFeeRemark":specialFeeRemark},
			beforeSend: function(){
				$("#confirmCommit").css("pointer-events", "none");
			},
			success:function(r){
				if(r.code==200){
					layerSettleResult("结算成功",1,year,month);
				}else{
					layerSettleResult(r.msg,2,null,null);
				}
				$("#confirmCommit").css("pointer-events", "auto");
			},
		})





	}

	/**
	 * 本月费用合计
	 * curAmt 本月费用
	 * balance 上月结余
	 */
	function getCurMonthTotalAmt(curAmt,balance){
		var curRealAmt = new BigDecimal(curAmt.toString());
		var balanceBd = new BigDecimal(balance.toString());
		if(balance>0){
			//上月结余是正的，计算上月结余-本月费用，如果大于0，则显示0; 如果小于0， 则本月费用-上月结余
			var tmpDiff = balanceBd.subtract(curRealAmt);
			tmpDiff = tmpDiff.setScale(2, MathContext.ROUND_HALF_UP).toString()
			if(parseFloat(tmpDiff)>0){
				return parseFloat(0);
			}else{
				//获取本月费用合计，本月费用-上月结余
				var tmpCurRealAmt = curRealAmt.subtract(balanceBd);
				tmpCurRealAmt = tmpCurRealAmt.setScale(2, MathContext.ROUND_HALF_UP).toString();
				return parseFloat(tmpCurRealAmt);
			}
		}else{
			//上月结余是负的，本月费用-上月结余
			//获取本月费用合计，本月费用-上月结余
			var tmpCurRealAmt = curRealAmt.subtract(balanceBd);
			tmpCurRealAmt = tmpCurRealAmt.setScale(2, MathContext.ROUND_HALF_UP).toString();
			return parseFloat(tmpCurRealAmt);
		}
	}


	/**
	 * 本月结余
	 * curRealPayAmt 本月实缴
	 * curAmt	 	 本月费用
	 * lastBalance   上月结余
	 */
	function getCurMonthBalance(curRealPayAmt,curAmt,lastBalance){
		//本月结余=本月实缴-本月费用+上月结余
		var curRealPayAmtBd = new BigDecimal(curRealPayAmt.toString());
		var curAmtBd = new BigDecimal(curAmt.toString());
		var lastBalanceBd = new BigDecimal(lastBalance.toString());
		var curBalance = curRealPayAmtBd.subtract(curAmtBd).add(lastBalanceBd);
		curBalance = curBalance.setScale(2, MathContext.ROUND_HALF_UP).toString();
		return parseFloat(curBalance);
	}

	/**
	 * layer结算结果弹出
	 * @param msg
	 * @param type
	 */
	function layerSettleResult(msg,type,year,month){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				if(type==1){
					layer.msg(msg, {icon: type, time:1500},function(){
						//获取用户月结算信息
						getUserMonthSettleInfo(year,month);
					});
				}else{
					layer.msg(msg, {icon: type, time:3000},function(){

					});
				}

			})
		});
	}

	/**
	 * layer缴费结果弹出
	 * @param msg
	 * @param type
	 */
	function layerPayResult(msg,type,year,month){
		var layer;
		layui.use(['layer'], function() {
			layer = layui.layer;
			layer.ready(function(){
				if(type==1){
					layer.msg(msg, {icon: type, time:1500},function(){
						//刷新缴费列表
						//$(".layui-laypage-btn").click();
						pay_bilListGenerate();
						//获取用户月结算信息
						getUserMonthSettleInfo(year,month);
					});
				}else{
					layer.msg(msg, {icon: type, time:3000},function(){

					});
				}

			})
		});
	}

	/**
	 * 打开缴费弹窗
	 */
	function layerBillPay(){
		var html='';
		html+='<div id="pop-con">';
		html+='<div class="pop-up">';
		html+='<div>';
		html+='<div class="pop-title relative overflow mb15px">';
		html+='<span class="ml15px">新增缴费记录</span>';
		html+='<p class="right"><img style="cursor: pointer;" src="'+basePath+'/static/img/close_icon.png" class="block pop-close"><p>';
		html+='</div>';
		html+='<div class="pop-form pop-form-bed mt30px mb30px">';
		html+='<div class="layui-form-item">';
		html+='<label style="width: 120px" class="layui-form-label border-box"><span class="red">*</span>缴费金额（元）：</label>';
		html+='<div class="layui-input-block">';
		html+='<input type="text" style="width: 320px" maxlength="5" id="payBillAmt" onkeyup="value=value.replace(/[^\\d]|^0/g,\'\')" placeholder="请输入" class="layui-input">';
		html+='</div>';
		html+='</div>';
		html+='<div class="layui-form-item">';
		html+='<label style="width: 120px" class="layui-form-label border-box"><span class="red">*</span>缴费时间：</label>';
		html+='<div class="layui-input-block">';
		html+='<input type="text"style="width: 320px" id="payBillDate" placeholder="请选择" class="layui-input layui-time select-bill-date">';
		html+='</div>';
		html+='</div>';
		html+='</div>';
		html+='<div class="btn-con textCenter">';
		html+='<span class="bill-btn-one" style="background-color: #fafafa;border: 1px solid #ddd; color: #666;cursor: pointer;">取&nbsp;消</span>';
		html+='<span class="bill-btn-two" style="background-color: #1C9399;color: #fff;cursor: pointer;">提&nbsp;交</span>';
		html+='</div>';
		html+='</div>';
		html+='</div>';

		var userNo = '[[${elderlyInfoOfBase.elderlyInfo.userNo}]]';
		$.ajax({
			type:"post",
			url:basePath+"/bill/getUserBillAbleDay",
			dataType:"json",
			async: false,
			data:{"userNo":userNo},
			success:function(r) {
				if (r.code == 200) {
					var startDay = r.data;
					var index = layer.open({
						type: 1,
						title: false, //不显示标题栏
						closeBtn: false,
						area: ['500px', ''],
						shade: 0.6,
						id: 'paybillCons', //设定一个id，防止重复弹出
						/*,btn: ['确认支付']*/
						btnAlign: 'c',
						moveType: 1, //拖拽模式，0或者1
						shadeClose: true, //设置允许点遮罩关闭
						content: html,
						success: function() {
							//时间初始化
							layui_billTimeInit('select-bill-date',startDay);
							//关闭弹层
							$(".pop-close").unbind().click(function() {
								layer.closeAll();
							});
							$(".bill-btn-one").unbind().click(function(){
								layer.closeAll();
							})
							$(".bill-btn-two").unbind().click(function(){
								var payBillAmt = $("#payBillAmt").val();
								var payBillDate = $("#payBillDate").val();
								confirmPay(payBillAmt, payBillDate);
							})


						},

					});
				}
			}
		})

	}

	/**
	 * 确认缴费
	 */
	function confirmPay(payBillAmt, payBillDate){
		var args=[];
		args.push(payBillAmt);
		args.push(payBillDate);
		confirmCon("确认要缴费吗？",payCommit, args);
	}

	/**
	 * 缴费提交
	 * payBillAmt    账单支付金额
	 * payBillDate   账单支付日期
	 */
	function payCommit(payBillAmt, payBillDate){
		payBillDate = payBillDate.replace(/-/g, "");		//转成正确的时间格式
		var userNo = '[[${elderlyInfoOfBase.elderlyInfo.userNo}]]';  //用户编号

		$.ajax({
			type:"post",
			url:basePath+"/bill/createPaymentRecord",
			dataType:"json",
			async: false,
			data:{"userNo":userNo,"paymentCount":payBillAmt,"paymentDay":payBillDate},
			beforeSend: function(){
				$("#confirmCommit").css("pointer-events", "none");
			},
			success:function(r){
				if(r.code==200){
					var year = $("#initYear").val();							 //账单年份
					var month = $("#initMonth").val();							 //账单月份
					layerPayResult("缴费成功",1,year,month);
				}else{
					layerPayResult("缴费失败",2,null,null);
				}
				$("#confirmCommit").css("pointer-events", "auto");
			},
			error:function(r){
				console.log(r);
			}
		})
	}

	/**
	 * 缴费明细列表初始化
	 */
	function pay_bilListGenerate(){
		var startDay=$("#startDay").val();
		if(!isNull(startDay)){
			startDay=startDay.replace(/-/g,"");
		}
		var endDay=$("#endDay").val();
		if(!isNull(endDay)){
			endDay=endDay.replace(/-/g,"");
		}
		var userNo = '[[${elderlyInfoOfBase.elderlyInfo.userNo}]]';

		layui.use(['table'], function() {
			var table = layui.table;
			//第一个实例
			table.render({
				elem: '#paybillList',
				url: '../bill/getBillList',
				where:{"startDay":startDay,"endDay":endDay,"userNo":userNo},
				page: true, //开启分页
				limit: 10,
				limits: [5,10,20],
				cols: [
					[ //表头
						// {
						// 	type: 'checkbox',
						// 	fixed: 'left'
						// },
						{
							field: 'id',
							title: '序号',
							fixed: 'left',
							type: 'numbers',
							width: 80,
						}, {
							field: 'PAYMENT_COUNT',
							title: '缴费金额（元）',
						}, {
							field: 'PAYMENT_DAY',
							title: '缴费时间',
						}, {
							field: 'TELLER_NAME',
							title: '操作者',
						}, {
							field: 'CREATE_TIME',
							title: '操作时间',
						}
					]
				],
				done: function(res, curr, count){
					$("#payBillTotal").html(count);
				}
			});

		});
	}


	/**
	 * 账单时间初始化
	 * name  	  class类名字
	 * startDay   最小可选择时间
	 */
	function layui_billTimeInit(name, startDay){
		layui.use(['laydate'], function() {
			var laydate = layui.laydate;
			laydate.render({
				elem: '.'+name,
				trigger: 'click',
				min:startDay,
				max:getCurDate(),
			});
		});
	}

	//获取今天的时间
	function getCurDate(){
		//今天的时间
		var day2 = new Date();
		day2.setTime(day2.getTime());
		var s2 = day2.getFullYear()+"-" + (day2.getMonth()+1) + "-" + day2.getDate();
		return s2;
	}




</script>

</html>
